<template>
  <div class="fx-loading" :style="loadingStyle">
    <div class="fx-loading-center">
      <ul class="fx-loading-rainbow" v-if="loadingType==='rainbow'">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
      <ul class="fx-loading-wave" v-else-if="loadingType==='wave'">
        <li></li>
        <li></li>
      </ul>
      <div class="fx-loading-text" v-if="text&&text!==''">{{ text }}</div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'

export type LoadingType = 'wave' | 'rainbow'

export interface LoadingProps {
  text: string;
  bgColor: string;
  textColor: string;
  loadingType: LoadingType;
}

export default defineComponent({
  name: 'FLoading',
  props: {
    text: {
      type: String as PropType<string>,
      default: null
    },
    bgColor: {
      type: String as PropType<string>,
      default: 'rgba(0, 0, 0, .8)'
    },
    textColor: {
      type: String as PropType<string>,
      default: '#fff'
    },
    loadingType: {
      type: String as PropType<LoadingType>,
      default: 'wave'
    }
  },
  setup (props: LoadingProps) {
    const loadingStyle = computed(() => {
      return {
        backgroundColor: props.bgColor,
        color: props.textColor
      }
    })

    return {
      loadingStyle
    }
  }
})
</script>
